use Tiles;


package Map;


our $accesor = sub{
    my $obj = shift;
    my ($attrname, $newval) = (shift, shift);

    if(defined($attrname) && defined($newval)){
	$obj->{$attrname} = $newval;
    }

    return $obj->{$attrname} if(defined($attrname));
    return "";
};

sub new{
    my $class = shift;
    my $self = {};

    bless $self, $class;
    $self->init(@_);

    return $self;
}


sub init{
    my $self = shift;
    my $tiles = shift;

    my $w = scalar(@{$tiles});
    my $h = scalar(@{$tiles->[0]});

    $self->{WIDTH}  = $w;
    $self->{HEIGHT} = $h;

    $self->{TILES} = $tiles;
} # init


sub height{
    my ($self, $newval) = (shift, shift);
    &$accesor($self, 'HEIGHT');
}

sub width{
    my ($self, $newval) = (shift, shift);
    &$accesor($self, 'WIDTH');
}


# Returns the ACTUAL tiles list, not a copy
# All changes to the tiles, including replacing 
# the tiles is inmediately effective
sub tiles{
    my ($self, $newval) = (shift, shift);
    &$accesor($self, 'TILES', $newval);
}

1;
